<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 7.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next-haha.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next-haha.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next-haha.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.0/css/all.min.css" integrity="sha256-VHqXKFhhMxcpubYf9xiWdCiojEbY9NexQ4jh8AxbvcM=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"ming.theyan.gs","root":"/","images":"/images","scheme":"Pisces","darkmode":false,"version":"8.25.0","exturl":false,"sidebar":{"position":"left","width_expanded":320,"width_dual_column":240,"display":"post","padding":18,"offset":12},"hljswrap":true,"codeblock":{"theme":{"light":"default","dark":"stackoverflow-dark"},"prism":{"light":"prism","dark":"prism-dark"},"copy_button":{"enable":false,"style":null},"fold":{"enable":false,"height":500},"language":false},"bookmark":{"enable":true,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":false,"duration":200,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"top_n_per_article":1,"unescape":false,"preload":false,"trigger":"auto"}}</script><script src="/js/config.js" defer></script>

    <meta name="description" content="乍一看，题都不难，但手生了后好多不看 manual 都生写不出来。 没啥可说的，直接上问题。">
<meta property="og:type" content="article">
<meta property="og:title" content="面试之查漏补缺">
<meta property="og:url" content="https://ming.theyan.gs/2020/09/%E9%9D%A2%E8%AF%95%E7%9F%A5%E8%AF%86%E7%82%B9%E6%9F%A5%E6%BC%8F%E8%A1%A5%E7%BC%BA/index.html">
<meta property="og:site_name" content="运维烂笔头">
<meta property="og:description" content="乍一看，题都不难，但手生了后好多不看 manual 都生写不出来。 没啥可说的，直接上问题。">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-09-11T13:43:27.000Z">
<meta property="article:modified_time" content="2020-09-13T14:32:34.000Z">
<meta property="article:author" content="老杨">
<meta property="article:tag" content="MySQL">
<meta property="article:tag" content="ss">
<meta property="article:tag" content="sed">
<meta property="article:tag" content="nginx">
<meta property="article:tag" content="iptables">
<meta property="article:tag" content="tr">
<meta property="article:tag" content="grep">
<meta property="article:tag" content="联合索引">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="https://ming.theyan.gs/2020/09/%E9%9D%A2%E8%AF%95%E7%9F%A5%E8%AF%86%E7%82%B9%E6%9F%A5%E6%BC%8F%E8%A1%A5%E7%BC%BA/">


<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://ming.theyan.gs/2020/09/%E9%9D%A2%E8%AF%95%E7%9F%A5%E8%AF%86%E7%82%B9%E6%9F%A5%E6%BC%8F%E8%A1%A5%E7%BC%BA/index.html","path":"2020/09/面试知识点查漏补缺/index.html","title":"面试之查漏补缺"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>面试之查漏补缺 | 运维烂笔头</title>
  
    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-106574959-2"></script>
  <script class="next-config" data-name="google_analytics" type="application/json">{"tracking_id":"UA-106574959-2","only_pageview":false,"measure_protocol_api_secret":null}</script>
  <script src="/js/third-party/analytics/google-analytics.js" defer></script>

  <script src="/js/third-party/analytics/baidu-analytics.js" defer></script>
  <script async src="https://hm.baidu.com/hm.js?fdef9ded31bdb8b2dab08eddebdd5fed"></script>







  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous" defer></script>
<script src="/js/utils.js" defer></script><script src="/js/motion.js" defer></script><script src="/js/sidebar.js" defer></script><script src="/js/next-boot.js" defer></script><script src="/js/bookmark.js" defer></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.5.0/search.js" integrity="sha256-xFC6PJ82SL9b3WkGjFavNiA9gm5z6UBxWPiu4CYjptg=" crossorigin="anonymous" defer></script>
<script src="/js/third-party/search/local-search.js" defer></script>







  




<!-- google adsense -->
<script data-ad-client="ca-pub-1045025618858716" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>

  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<link rel="alternate" href="/atom.xml" title="运维烂笔头" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">运维烂笔头</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">一个 SA 老兵的工作日志</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-projects"><a href="/projects" rel="section"><i class="fa fa-code fa-fw"></i>projects</a></li><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a></li><li class="menu-item menu-item-sitemap"><a href="/sitemap.xml" rel="section"><i class="fa fa-sitemap fa-fw"></i>站点地图</a></li><li class="menu-item menu-item-commonweal"><a href="/404/" rel="section"><i class="fa fa-heartbeat fa-fw"></i>公益 404</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
      <div class="search-header">
        <span class="search-icon">
          <i class="fa fa-search"></i>
        </span>
        <div class="search-input-container">
          <input autocomplete="off" autocapitalize="off" maxlength="80"
                placeholder="搜索..." spellcheck="false"
                type="search" class="search-input">
        </div>
        <span class="popup-btn-close" role="button">
          <i class="fa fa-times-circle"></i>
        </span>
      </div>
      <div class="search-result-container">
        <div class="search-result-icon">
          <i class="fa fa-spinner fa-pulse fa-5x"></i>
        </div>
      </div>
    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%89%BE%E5%87%BA%E6%96%87%E4%BB%B6%E4%B8%AD%E7%A9%BA%E8%A1%8C%E7%9A%84%E8%A1%8C%E5%8F%B7"><span class="nav-number">1.</span> <span class="nav-text">找出文件中空行的行号</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%8A%8A%E6%96%87%E4%BB%B6%E4%B8%AD%E6%89%80%E6%9C%89%E7%9A%84%E6%8D%A2%E8%A1%8C%E6%9B%BF%E6%8D%A2%E6%88%90%E7%A9%BA%E6%A0%BC"><span class="nav-number">2.</span> <span class="nav-text">把文件中所有的换行替换成空格</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#sed"><span class="nav-number">2.1.</span> <span class="nav-text">sed</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#tr"><span class="nav-number">2.2.</span> <span class="nav-text">tr</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8B%E7%8A%B6%E6%80%81%E6%98%AF-established-%E7%9A%84%E8%BF%9E%E6%8E%A5"><span class="nav-number">3.</span> <span class="nav-text">查看状态是 established 的连接</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E9%98%B2%E7%81%AB%E5%A2%99%E8%AE%BE%E7%BD%AE"><span class="nav-number">4.</span> <span class="nav-text">防火墙设置</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Nginx-%E4%BC%98%E5%8C%96%E9%85%8D%E7%BD%AE%E7%82%B9"><span class="nav-number">5.</span> <span class="nav-text">Nginx 优化配置点</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#work-processes"><span class="nav-number">5.1.</span> <span class="nav-text">work processes</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#worker-processes"><span class="nav-number">5.1.1.</span> <span class="nav-text">worker_processes</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#worker-connections"><span class="nav-number">5.1.2.</span> <span class="nav-text">worker_connections</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Keepalive-Connections"><span class="nav-number">5.2.</span> <span class="nav-text">Keepalive Connections</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#keepalive-requests"><span class="nav-number">5.2.1.</span> <span class="nav-text">keepalive_requests</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#keepalive-timeout"><span class="nav-number">5.2.2.</span> <span class="nav-text">keepalive_timeout</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#keepalive"><span class="nav-number">5.2.3.</span> <span class="nav-text">keepalive</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#sendfile"><span class="nav-number">5.3.</span> <span class="nav-text">sendfile</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#caching"><span class="nav-number">5.4.</span> <span class="nav-text">caching</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#compression"><span class="nav-number">5.5.</span> <span class="nav-text">compression</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#MySQL-%E7%9A%84%E8%81%94%E5%90%88%E7%B4%A2%E5%BC%95"><span class="nav-number">6.</span> <span class="nav-text">MySQL 的联合索引</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#MySQL-%E7%9A%84%E4%B8%BB%E4%BB%8E%E5%A4%8D%E5%88%B6%EF%BC%88%E5%90%8C%E6%AD%A5%EF%BC%89"><span class="nav-number">7.</span> <span class="nav-text">MySQL 的主从复制（同步）</span></a></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">老杨</p>
  <div class="site-description" itemprop="description">好记性比不过烂笔头</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">114</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">8</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags/">
        <span class="site-state-item-count">509</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/haw-haw" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;haw-haw" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:blog@theyan.gs" title="E-Mail → mailto:blog@theyan.gs" rel="noopener me" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://weibo.com/u/1494877243" title="Weibo → https:&#x2F;&#x2F;weibo.com&#x2F;u&#x2F;1494877243" rel="noopener me" target="_blank"><i class="fab fa-weibo fa-fw"></i>Weibo</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://twitter.com/6fool" title="Twitter → https:&#x2F;&#x2F;twitter.com&#x2F;6fool" rel="noopener me" target="_blank"><i class="fab fa-twitter fa-fw"></i>Twitter</a>
      </span>
  </div>

        </div>
      </div>
    </div>

    
    <div class="sidebar-inner sidebar-blogroll">
      <div class="links-of-blogroll animated">
        <div class="links-of-blogroll-title"><i class="fa fa-globe fa-fw"></i>
          链接
        </div>
        <ul class="links-of-blogroll-list">
            <li class="links-of-blogroll-item">
              <a href="https://bad-pencil.github.io/" title="https:&#x2F;&#x2F;bad-pencil.github.io" rel="noopener" target="_blank">github 镜像站</a>
            </li>
            <li class="links-of-blogroll-item">
              <a href="https://hawhaw.gitee.io/" title="https:&#x2F;&#x2F;hawhaw.gitee.io" rel="noopener" target="_blank">gitee 镜像站</a>
            </li>
        </ul>
      </div>
    </div>
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://ming.theyan.gs/2020/09/%E9%9D%A2%E8%AF%95%E7%9F%A5%E8%AF%86%E7%82%B9%E6%9F%A5%E6%BC%8F%E8%A1%A5%E7%BC%BA/index.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="老杨">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="运维烂笔头">
      <meta itemprop="description" content="好记性比不过烂笔头">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="面试之查漏补缺 | 运维烂笔头">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          面试之查漏补缺
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2020-09-11 21:43:27" itemprop="dateCreated datePublished" datetime="2020-09-11T21:43:27+08:00">2020-09-11</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2020-09-13 22:32:34" itemprop="dateModified" datetime="2020-09-13T22:32:34+08:00">2020-09-13</time>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><p>乍一看，题都不难，但手生了后好多不看 manual 都生写不出来。</p>
<p>没啥可说的，直接上问题。</p>
<span id="more"></span>

<h2 id="找出文件中空行的行号"><a href="#找出文件中空行的行号" class="headerlink" title="找出文件中空行的行号"></a>找出文件中空行的行号</h2><p>答：用 grep 配合参数 -n 显示行号，具体命令：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">grep -n <span class="string">&quot;^$&quot;</span> file</span><br></pre></td></tr></table></figure>

<h2 id="把文件中所有的换行替换成空格"><a href="#把文件中所有的换行替换成空格" class="headerlink" title="把文件中所有的换行替换成空格"></a>把文件中所有的换行替换成空格</h2><h3 id="sed"><a href="#sed" class="headerlink" title="sed"></a>sed</h3><p>答：用 sed 命令来把文件合成一行以后再替换，详见命令：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sed -e <span class="string">&#x27;1h;2,$H;$!d;g;s/\n/ /g&#x27;</span> file</span><br></pre></td></tr></table></figure>

<h3 id="tr"><a href="#tr" class="headerlink" title="tr"></a>tr</h3><p>答：用 tr 命令替换 ‘\n’ 为 ‘ ‘，详见命令：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">tr</span> <span class="string">&#x27;\n&#x27;</span> <span class="string">&#x27; &#x27;</span> &lt; file | sed <span class="string">&#x27;s/ $/\n/&#x27;</span></span><br></pre></td></tr></table></figure>

<h2 id="查看状态是-established-的连接"><a href="#查看状态是-established-的连接" class="headerlink" title="查看状态是 established 的连接"></a>查看状态是 established 的连接</h2><p>答：用 ss 命令：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ss -t state established</span><br></pre></td></tr></table></figure>

<h2 id="防火墙设置"><a href="#防火墙设置" class="headerlink" title="防火墙设置"></a>防火墙设置</h2><p>规则要求：</p>
<ul>
<li>对所有地址开放本服务器的80端口、10~20端口。</li>
<li>其他机器可以用ping命令来探测本服务器的链接情况</li>
<li>其他没有被准许的端口将禁止访问</li>
</ul>
<p>答：用 iptables，具体如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">iptables -A INPUT -p tcp -m multiport --dports 10:20,80 -j ACCEPT</span><br><span class="line">iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT</span><br><span class="line">iptables -A INPUT -j REJECT</span><br></pre></td></tr></table></figure>

<h2 id="Nginx-优化配置点"><a href="#Nginx-优化配置点" class="headerlink" title="Nginx 优化配置点"></a>Nginx 优化配置点</h2><h3 id="work-processes"><a href="#work-processes" class="headerlink" title="work processes"></a>work processes</h3><h4 id="worker-processes"><a href="#worker-processes" class="headerlink" title="worker_processes"></a>worker_processes</h4><p>Nginx worker 的进程数，缺省为 1；推荐设为 auto，将实现每颗 cpu 核跑一个 worker 进程</p>
<h4 id="worker-connections"><a href="#worker-connections" class="headerlink" title="worker_connections"></a>worker_connections</h4><p>每个 worker 进程可以同时处理的最大连接数。</p>
<h3 id="Keepalive-Connections"><a href="#Keepalive-Connections" class="headerlink" title="Keepalive Connections"></a>Keepalive Connections</h3><h4 id="keepalive-requests"><a href="#keepalive-requests" class="headerlink" title="keepalive_requests"></a>keepalive_requests</h4><p>客户端可以通过单个 keepalive 连接进行的请求数，可以酌情调大。</p>
<h4 id="keepalive-timeout"><a href="#keepalive-timeout" class="headerlink" title="keepalive_timeout"></a>keepalive_timeout</h4><p>酌情调整</p>
<h4 id="keepalive"><a href="#keepalive" class="headerlink" title="keepalive"></a>keepalive</h4><p>每个 worker 进程保持与上游服务器 keepalive 的空闲连接数，注意，要启用这个，需要同时配置如下设置：</p>
<figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">proxy_http_version</span> <span class="number">1</span>.<span class="number">1</span>;</span><br><span class="line"><span class="attribute">proxy_set_header</span> Connection <span class="string">&quot;&quot;</span>;</span><br></pre></td></tr></table></figure>

<h3 id="sendfile"><a href="#sendfile" class="headerlink" title="sendfile"></a>sendfile</h3><p>操作系统的 sendfile（） 系统调用将数据从一个文件描述符复制到另一个文件描述符，通常实现零复制，这可以加快 TCP 数据传输的速度</p>
<h3 id="caching"><a href="#caching" class="headerlink" title="caching"></a>caching</h3><p>启用缓存，您可以大大缩短对客户端的响应时间，同时可以大大减少后端服务器的负载</p>
<h3 id="compression"><a href="#compression" class="headerlink" title="compression"></a>compression</h3><p>压缩发送给客户端的响应可以大大减小客户端的大小，因此它们使用较少的网络带宽。需要注意的是：启用压缩会消耗 CPU 资源，如果服务器的 CPU 资源是瓶颈的话慎用。还有，本来已经压缩过的内容（如图片）不要启用</p>
<h2 id="MySQL-的联合索引"><a href="#MySQL-的联合索引" class="headerlink" title="MySQL 的联合索引"></a>MySQL 的联合索引</h2><p>联合索引又叫复合索引，是多个字段组成的一条索引。</p>
<ul>
<li>联合索引的最左前缀匹配是指 where 条件一定要有联合索引的第一个字段</li>
<li>是否走联合索引跟 where 条件的顺序无关</li>
<li>遇到范围查询(&gt;、&lt;、between、like)就会停止匹配</li>
</ul>
<h2 id="MySQL-的主从复制（同步）"><a href="#MySQL-的主从复制（同步）" class="headerlink" title="MySQL 的主从复制（同步）"></a>MySQL 的主从复制（同步）</h2><p>先决条件：</p>
<ol>
<li>master 上启用 binlog</li>
</ol>
<p>原理：</p>
<ol>
<li>master 上 binglog dump 线程将 binlog 的变化内容发给 slave</li>
<li>slave 上的 I&#x2F;O 线程收到 master 上发过来的 binlog 内容后，写入本地的 relay log</li>
<li>slave 上的 SQL 线程读取 relay log，并根据其内容回放到 slave</li>
</ol>

    </div>

    
    
    

    <footer class="post-footer">
          <div class="reward-container">
  <div>请我一杯咖啡吧！</div>
  <button>
    赞赏
  </button>
  <div class="post-reward">
      <div>
        <img src="/images/wechat-reward.png" alt="老杨 微信">
        <span>微信</span>
      </div>
      <div>
        <img src="/images/alipay-reward.png" alt="老杨 支付宝">
        <span>支付宝</span>
      </div>

  </div>
</div>

          <div class="followme">
  <span>欢迎关注我的其它发布渠道</span>

  <div class="social-list">

      <div class="social-item">
          <a target="_blank" class="social-link" href="https://twitter.com/6fool">
            <span class="icon">
              <i class="fab fa-twitter"></i>
            </span>

            <span class="label">Twitter</span>
          </a>
      </div>

      <div class="social-item">
          <a target="_blank" class="social-link" href="/atom.xml">
            <span class="icon">
              <i class="fa fa-rss"></i>
            </span>

            <span class="label">RSS</span>
          </a>
      </div>
  </div>
</div>

          <div class="post-tags">
              <a href="/tags/MySQL/" rel="tag"># MySQL</a>
              <a href="/tags/ss/" rel="tag"># ss</a>
              <a href="/tags/sed/" rel="tag"># sed</a>
              <a href="/tags/nginx/" rel="tag"># nginx</a>
              <a href="/tags/iptables/" rel="tag"># iptables</a>
              <a href="/tags/tr/" rel="tag"># tr</a>
              <a href="/tags/grep/" rel="tag"># grep</a>
              <a href="/tags/%E8%81%94%E5%90%88%E7%B4%A2%E5%BC%95/" rel="tag"># 联合索引</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/2020/08/%E7%94%A8%20Python%20%E5%AE%9E%E7%8E%B0%E7%AE%80%E5%8D%95%E7%9A%84%E4%BF%84%E7%BD%97%E6%96%AF%E6%96%B9%E5%9D%97%EF%BC%88tetris%EF%BC%89%E6%B8%B8%E6%88%8F/index.html" rel="prev" title="用 Python 实现简单的俄罗斯方块（tetris）游戏">
                  <i class="fa fa-angle-left"></i> 用 Python 实现简单的俄罗斯方块（tetris）游戏
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/2020/10/How-to-install-or-upgrade-fomula-from-local-dmg-file/index.html" rel="next" title="How to install&#x2F;upgrade fomula from local dmg file">
                  How to install/upgrade fomula from local dmg file <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 
    <span itemprop="copyrightYear">2025</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">老杨</span>
  </div>
  <div class="powered-by">由 <a href="https://hexo.io/" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/pisces/" rel="noopener" target="_blank">NexT.Pisces</a> 强力驱动
  </div>

    </div>
  </footer>

  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>
  <div class="sidebar-dimmer"></div>
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>
  <a role="button" class="book-mark-link book-mark-link-fixed"></a>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>

</body>
</html>
